package util;

import java.math.BigDecimal;

public class DoubleUtil {

	private DoubleUtil() {}
	
	/**
	 * 操作：double数据的相加.<br>
	 * 刘柱栋    2013-4-8
	 * @param val1
	 * @param val2
	 * @return
	 */
	public static double add(double val1 , double val2){
		BigDecimal value1 = new BigDecimal(Double.toString(val1));
		BigDecimal value2 = new BigDecimal(Double.toString(val2));
		
		return value1.add(value2).doubleValue();
	}
	
	/**
	 * 操作：double数据的相减.<br>
	 * 刘柱栋    2013-4-8
	 * @param val1
	 * @param val2
	 * @return
	 */
	public static double subtract(double val1 , double val2){
		BigDecimal value1 = new BigDecimal(Double.toString(val1));
		BigDecimal value2 = new BigDecimal(Double.toString(val2));
		
		return value1.subtract(value2).doubleValue();
	}
	
	/**
	 * 操作：double数据的相乘.<br>
	 * 刘柱栋    2013-4-8
	 * @param val1
	 * @param val2
	 * @return
	 */
	public static double multiply(double val1 , double val2){
		BigDecimal value1 = new BigDecimal(Double.toString(val1));
		BigDecimal value2 = new BigDecimal(Double.toString(val2));
		
		return value1.multiply(value2).doubleValue();
	}
	
	/**
	 * 操作：double数据相除.<br>
	 * 刘柱栋    2013-4-8
	 * @param val1
	 * @param val2
	 * @return
	 */
	public static double divide(double val1 , double val2){
		BigDecimal value1 = new BigDecimal(Double.toString(val1));
		BigDecimal value2 = new BigDecimal(Double.toString(val2));
		
		return value1.divide(value2).doubleValue();
	}

	/**
	 * 刘柱栋    2013-4-7
	 * @param args
	 */
	public static void main(String[] args) {
		System.out.println(add(0,0.05));
	}

}
